module.exports = function ($resource, $state, $http, $q, FileUploader, $modal, toaster, $stateParams) {
  
	return {

		restrict: 'AE',
		template: require('../views/approvallist.html'),
		replace: true,
		scope: {
			'saleobj': '=',
			'funobj': '=',
			'baseinfo': '=',
			'util': '=',
			'examineflag' : '='
		},
		link: function (scope, elements, attrs) {
			scope.type = $stateParams.type;
      scope.info = {};
      var params = {};
      var url = '';
      if (scope.type == '0'){
        url = '/api/as/ggc/reviewCityResponsible/approvalList';
        params = { // 市级
          'recommend_city' : '1',
          // 'project_state' : '3',
          'city_project' : '1'
        }
      } else if(scope.type == '1'){ // 区县
        url = '/api/as/ggc/reviewDistrictTourism/findByRecommendList'
        params = {
          'recommend_district' : '1',
          // 'project_state' : '1',
          'city_project' : '0'
        }
      }
			/* 分页
			* ========================================= */
			scope.maxSize = 5;             //最多显示多少个按钮
			scope.bigCurrentPage = 1;      //当前页码
      scope.itemsPerPage = 10         //每页显示几条
      scope.obj={};
      scope.d={};
      scope.searchform = {};
      scope.rsarr = [
        {name:'推荐',value:'1'},
        {name:'不推荐',value:'0'}
      ]
			
			scope.getlist = function () {
				var para = {
					pageNo:scope.bigCurrentPage, 
          pageSize:scope.itemsPerPage,
				};
				para = angular.extend(params, para, scope.searchform);
				$resource(url, {}, {}).
				save(para,function(res) {
					console.log(para);
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					console.log('接口返回值');
					scope.objs = res.data.results;
					scope.bigTotalItems = res.data.totalRecord;

					
				})
			};
			
			scope.getlist(); 

			scope.$watch('examineflag', function(){
				scope.getlist();
			}, true)
			
			// scope.getlist(); 

			scope.toinfo= function (index) {
        scope.item = scope.objs[index];
				var modalInstance = $modal.open({
					template: require('../views/projectinfo.html'),
					controller: 'projectinfo',
					size: 'lg',
					resolve: {
						items: function () {
							return scope.item;
            },
            type: function () {
							return scope.type;
						}
					}
				});
				modalInstance.result.then(function (showResult) {	
          scope.examineflag++;
				});
			}
			
      scope.rejectInfo= function (index) {
				console.log('尽力了')
				scope.item = scope.objs[index];
				var modalInstance = $modal.open({
					template: require('../views/reason.html'),
					controller: 'reason',
					size: 'lg',
					resolve: {
						items: function () {
							return scope.item;
            },
            type: function () {
							return scope.type;
						},
						flag: function () {
							return '1'
						}
					}
				});
				modalInstance.result.then(function (showResult) {
          scope.examineflag++;
				});
			}

    }
	}
}